//
//  NewsViewController.m
//  OnePointDemo
//
//  Created by 薛磊 on 2018/7/3.
//  Copyright © 2018年 XL. All rights reserved.
//

#import "NewsViewController.h"
#import "XL_NewsHeadView.h"
#import "DoctorNetmanager.h"

@interface NewsViewController ()<HeadViewButtonDelegate,UIScrollViewDelegate>
{
    NSInteger _index;
}
@property(nonatomic,strong)NSArray * titleArray;

@property(nonatomic,strong)UIScrollView * bottomScrollView;

@property(nonatomic,strong)XL_NewsHeadView * headView;

@end

@implementation NewsViewController

-(UIScrollView *)bottomScrollView{
    
    if (!_bottomScrollView) {
        
        _bottomScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 50, UIScreenWIDTH, UIScreenHEIGHT - 50)];
        
        _bottomScrollView.contentSize = CGSizeMake(UIScreenWIDTH * 6,UIScreenHEIGHT - 50 );
        
        _bottomScrollView.pagingEnabled = NO;
        
        _bottomScrollView.bounces = NO;
        
        _bottomScrollView.delegate = self;
        
        _bottomScrollView.scrollEnabled = YES;
        
        _bottomScrollView.showsHorizontalScrollIndicator = NO;
        
        [self.view addSubview:_bottomScrollView];
    }
    
    return _bottomScrollView;
}

-(NSArray *)titleArray{
    
    if (!_titleArray) {
        
        _titleArray = @[@"热点",@"健康",@"医疗",@"食品",@"生物",@"行业"];
        
    }
    
    return _titleArray;
}

-(void)jp_overloadNavItems{
    [super jp_overloadNavItems];
    
}
-(void)jp_setupUI{
    [super jp_setupUI];
    
    self.headView = [[XL_NewsHeadView alloc] initWithCreatViewArray:self.titleArray rect:CGRectMake(0, 0, UIScreenWIDTH, 50)];
    
    self.headView.delegate = self;
    
    [self.view addSubview:self.headView];
    
    [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(50);
    }];
    
    [self.bottomScrollView addSubview:self.tableView];
    
}
-(void)jp_requestData{
    [super jp_requestData];
    
    NSMutableDictionary * params = [NSMutableDictionary dictionary];
    
    params[@"type"] = @(1);
    
    [DoctorNetmanager postForQuiesceRequestWithInterface:@"MedicalCommonServlet" params:params successBlock:^(id response) {
        
        
    } errorBlock:^(NSString *errorMsg) {
        
    }];
    
    
    [self.bottomScrollView setBackgroundColor:[UIColor whiteColor]];
    
    [self.tableView reloadData];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 20;
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    JPBaseCell * cell = [JPBaseCell jp_cellForTableView:tableView];
    
    cell.textLabel.text = self.titleArray[_index];
    
    return cell;
}

//-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
//    if ([scrollView isKindOfClass:[UITableView class]]) {
//    } else {
//        //topScrollView没有指定代理对象，所以此代理方法不会响应
//        CGPoint offset = scrollView.contentOffset;
//        int index = offset.x / CGRectGetWidth(scrollView.bounds);
//        //        self.result = index;
//        UIButton *typeBtn = (UIButton *)[self.view viewWithTag:1001 + index];
//        
//        [self.headView btnClick:typeBtn];
//        
//        [self headViewClickButton:typeBtn];
//    }
//}

-(void)headViewClickButton:(UIButton *)button{
    
    _index = button.tag;
    
    [self.tableView reloadData];
}
@end
